package com.linked.goods.goodsbase.service.impl;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.linked.goods.goodsbase.bean.dto.GoodsVersionDTO;
import com.linked.goods.goodsbase.bean.po.GoodsVersionPO;
import com.linked.goods.goodsbase.mapper.IGoodsVersionMapper;
import com.linked.goods.goodsbase.service.IGoodsVersionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

/**
 * @author :dbq
 * @date : 2023/3/15 14:40
 * @description : desc
 */
@Service
@Slf4j
public class GoodsVersionServiceImpl implements IGoodsVersionService {

    private final IGoodsVersionMapper goodsVersionMapper;

    private final ObjectMapper mapper;

    public GoodsVersionServiceImpl(IGoodsVersionMapper goodsVersionMapper, ObjectMapper mapper) {
        this.goodsVersionMapper = goodsVersionMapper;
        this.mapper = mapper;
    }

    @Override
    public int saveGoodsVersionList(List<GoodsVersionPO> versionList) throws Exception {
        AtomicReference<Integer> count = new AtomicReference<>(0);
        versionList.stream().forEach(x -> count.updateAndGet(v -> v + goodsVersionMapper.insert(x)));
        return count.get();
    }

    @Override
    public boolean saveGoodsVersion(GoodsVersionPO param) throws Exception {
        return goodsVersionMapper.insert(param) > 0;
    }


}
